<?php
/**
 * 自定义辅助方法静态类
 * 
 * @author Dengwei
 *
 */
class OP_Util
{
    static $baseUrl;

    static $publicUrl;

    static  $absoluteUrl;

    /**
	* 获取绝对地址
	*
	* @static
	* @access public
	* @param $url 相对路径
	* @return String 绝对地址 
	* 
	*/
    public static function absoluteUrl($url='')
    {
        if (null === self::$absoluteUrl) {
            $serverUrl = new Zend_View_Helper_ServerUrl();
            self::$absoluteUrl = $serverUrl->serverUrl();
        }

        return self::$absoluteUrl . '/' . ($url ? ltrim($url, '/') : '');
    }

    /**
	 * 
	 * 获取当前路径
	 * 
	 * @param String $url
	 * @param bool $absolute
	 * @return String
	 */
    public static function baseUrl($url='', $absolute=true)
    {
        if (null === self::$baseUrl) {
            $request = new Zend_Controller_Request_Http();
            self::$baseUrl = $request->getBaseUrl();
        }

        return ($absolute ? self::absoluteUrl(self::$baseUrl) : self::$baseUrl) . '/' . ltrim($url, '/');
    }

    /**
	 * 获取项目发布路径
	 * 
	 * @param String $url
	 * @param bool $absolute
	 * @return String
	 */
    public static function publicUrl($url='', $absolute=true)
    {
        if (null === self::$publicUrl) {
            $request = new Zend_Controller_Request_Http();
            self::$publicUrl = $request->getBasePath();
        }
        
        return ($absolute ? self::absoluteUrl(self::$publicUrl) : self::$publicUrl) . '/' . ltrim($url, '/');
    }


}
?>